package cn.tedu.ivos.dict.service.impl;

import cn.tedu.ivos.dict.mapper.DictMapper;
import cn.tedu.ivos.dict.pojo.dto.AddDictParam;
import cn.tedu.ivos.dict.pojo.dto.DictQuery;
import cn.tedu.ivos.dict.pojo.entity.Dict;
import cn.tedu.ivos.dict.pojo.vo.DictVO;
import cn.tedu.ivos.dict.service.DictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class DictServiceImpl implements DictService {
    @Autowired
    DictMapper mapper;
    @Override
    public List<DictVO> dictSelect(DictQuery query) {
        log.debug("query:{}",query);
        List<DictVO> list = mapper.selectDict(query);
        return list;
    }

    @Override
    public void addDict(AddDictParam param) {
        log.debug("param:{}",param);
        Dict dict = new Dict();
        BeanUtils.copyProperties(param, dict);
        if(dict.getId()==null){
            dict.setStatus("1");
            dict.setCreateTime(new Date());
            mapper.insert(dict);
        }
        else{
            dict.setUpdateTime(new Date());
            mapper.update(dict);
        }
    }

    @Override
    public void deleteDict(Long id) {
        log.debug("删除字典业务，参数：{}", id);
        Dict dict = new Dict();
        dict.setId(id);
        dict.setStatus("0");//禁用
        dict.setUpdateTime(new Date());
        mapper.update(dict);
    }
}
